package com.wn.portal.controller;

import com.netflix.hystrix.contrib.javanica.annotation.DefaultProperties;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.wn.portal.feign.MemberFeignClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

/**
 * @author yellow Docter
 * @date 2022 -08-22
 * @desc
 */
@RestController
@RequestMapping("/feign")
@DefaultProperties(defaultFallback = "fallBack")    // 服务器降级调用那个方法
public class PorTalFeignController {

    @Autowired
    private MemberFeignClient memberFeignClient;

    @GetMapping("/{mid}")
    public String findMemberById(@PathVariable String mid){
        String str = memberFeignClient.findMemberById(mid);
        return str;
    }

    //超时测试
    @GetMapping("/test/{mid}")
    @HystrixCommand                  //开启服务降级
    public String findTimeOut(@PathVariable Integer mid){
        String str = memberFeignClient.findMemberTimeOut(mid);
        System.out.println("str = " + str);
        return str;
    }

    /**
     * 服务降级的方法的具体实现...
     * @return
     */
    public String fallBack(){
        return "服务降级的方法的实现...网络繁忙";
    }

}
